//
//  StatusCellBottomView.swift
//  SinaWeibo
//
//  Created by 张洪毓 on 15/11/15.
//  Copyright © 2015年 张洪毓. All rights reserved.
//

import UIKit
import SnapKit
class StatusCellBottomView: UIView {

    @objc private func retweetBtnDidClick() {
        let temp = TempViewController()
        retweetBtn.navController()?.pushViewController(temp, animated: true)
    }
    
    //MARk:  3. 重写父类的构造方法，调用setupUI
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.98, alpha: 1)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //MARk:  2. 设置UI
    private func setupUI() {
        //添加子控件
        addSubview(retweetBtn)
        addSubview(composeBtn)
        addSubview(likeBtn)
        
        let w: CGFloat = 0.5
        let scale = 0.4
        
        //设置约束
        retweetBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(snp_top)
            make.left.equalTo(snp_left)
            make.height.equalTo(snp_height)
        }
        
        //设置分割线1的约束
        let sepView1 = sepView()
        addSubview(sepView1)
        sepView1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetBtn.snp_right)
            make.height.equalTo(snp_height).multipliedBy(scale)
            make.width.equalTo(w)
            make.centerY.equalTo(self.snp_centerY)
        }

        composeBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(snp_top)
            make.left.equalTo(retweetBtn.snp_right)
            make.height.equalTo(snp_height)
            make.width.equalTo(retweetBtn.snp_width)
        }
        
        //设置分割线2的约束
        let sepView2 = sepView()
        addSubview(sepView2)
        sepView2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(composeBtn.snp_right)
            make.height.equalTo(snp_height).multipliedBy(scale)
            make.width.equalTo(w)
            make.centerY.equalTo(self.snp_centerY)
        }
        
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(snp_top)
            make.left.equalTo(composeBtn.snp_right)
            make.right.equalTo(snp_right)
            make.height.equalTo(snp_height)
            make.width.equalTo(composeBtn.snp_width)
        }
 
        retweetBtn.addTarget(self, action: "retweetBtnDidClick", forControlEvents: .TouchUpInside)
    }
    
    
    //创建分割线
    private func sepView() -> UIView {
        let viewer = UIView()
        viewer.backgroundColor = UIColor.darkGrayColor()
        return viewer
    }
    
    //MARk:  1. 懒加载所有控件
    private lazy var retweetBtn: UIButton = UIButton(title: "转发", backImage: nil, color: UIColor.darkGrayColor(),image: "timeline_icon_retweet",size: 10)
    private lazy var composeBtn: UIButton = UIButton(title: "评论", backImage: nil, color: UIColor.darkGrayColor(), image: "timeline_icon_comment", size: 10)
    private lazy var likeBtn: UIButton = UIButton(title: "赞", backImage: nil, color: UIColor.darkGrayColor(), image: "timeline_icon_unlike", size: 10)

}
